package com.matt.repository.impl;

import com.matt.repository.base.BaseNativeSqlRepository;
import com.matt.repository.base.MultiEvaluatingCERecordRepository;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/9/20
 * *******************************
 */
@Component
public class MultiEvaluatingCERecordRepositoryImpl extends BaseNativeSqlRepository implements MultiEvaluatingCERecordRepository{

    @Override
    public List<Object[]> findByEvaluatingCERecordId(String evaluatingCERecordId) {

        String findSql = String.format("SELECT evaluatingCEAbility as ability, sum(score) as totalScore, count(id) as count" +
                " from evaluating_ce_question_record  " +
                " where evaluatingCERecordId='%s' GROUP BY evaluatingCEAbility", evaluatingCERecordId);

        List<Object[]> objectArrayList = sqlArrayList(findSql);
        return objectArrayList;
    }

    @Override
    public Object[] findCourseByEvaluatingCERecordId(String evaluatingCERecordId) {
        String sql=String.format("select p.earlyTitle, p.earlyWeek, p.courseDate " +
                " from evaluating_ce_record r LEFT JOIN children_course_item i ON i.evaluatingCERecordId = r.id" +
                " LEFT JOIN course_plan p on i.coursePlanId = p.id " +
                "where r.id = '%s' ", evaluatingCERecordId);
        List<Object[]> objectArrayList = sqlArrayList(sql);
        return objectArrayList.get(0);
    }
}
